/**
  ******************************************************************************
  * @file    usb2can_driver.h
  * @author  vincent
  * @version V1.0.0
  * @date    2018/10/09
  * @brief   This file provides main functions.
  ******************************************************************************
  * @attention
  *
  * 
  ******************************************************************************
  */


#ifndef __USB2CAN_DRIVER_H__
#define __USB2CAN_DRIVER_H__

/* Includes ------------------------------------------------------------------*/

#include "ECanVci.h"

/* Prama define discrible -----------------------------------------------------*/

#define CAN_RX_MSG_BUF          ((int)128)
#define CAN_TX_MSG_BUF          ((int)128)
#define CAN_MSG_LEN             ((int)8)   


/* Data strcut redefine  -----------------------------------------------------*/

typedef BOARD_INFO              board_info;
typedef CAN_OBJ                 can_obj;
typedef CAN_STATUS              can_status;
typedef INIT_CONFIG             can_config;
typedef FILTER_RECORD           can_filter;

/* Prama  discrible ---------------------------------------------------------*/



/* strcuct  discrible --------------------------------------------------------*/

typedef enum
{
    statu_err = (int)0,
    statu_ok =  (int)1,
}function;

//usb转can的硬件类型
typedef enum
{
  can2usb_i = USBCAN1,
  can2usb_ii = USBCAN2,
}device_type;

//CAN通信波特率
typedef enum
{
  kbps_100 = 0x1C04,
  kbps_125 = 0x1C03,
  kbps_200 = 0xFA81,
  kbps_250 = 0x1C01,
  kbps_400 = 0xFA80,
  kbps_500 = 0x1C00,
  kbps_666 = 0xB680,
  kbps_800 = 0x1600,
  kbps_1000 = 0x1400, 
}can_baud;

/* 设备信息结构体*/
typedef struct 
{
	unsigned int	    device_type;
	unsigned int	    device_index;
	unsigned int	    can_index;
    unsigned int        can_channel;  
	BOARD_INFO          board_info;
    CAN_OBJ             can_rx_obj[CAN_RX_MSG_BUF];
    CAN_OBJ             can_tx_obj[CAN_TX_MSG_BUF];
    CAN_STATUS          can_status;
    INIT_CONFIG         can_config;
    FILTER_RECORD       can_filter;    
}can_device;

/*消息报文结构体*/
typedef struct
{
    unsigned int    id;
    unsigned int    len;
    unsigned char   msg[CAN_MSG_LEN];
}can_msg;

/*消息集结构体*/
typedef struct
{
    unsigned int    total_count;
    can_msg         can_msg_buf[CAN_RX_MSG_BUF];   
}can_msg_package;

/* Public fucntion  discrible -----------------------------------------------*/

can_device device_can_init(void);
function device_can_open(can_device device_name);
function device_can_info_get(can_device device_name);
function device_can_close(can_device device_name);
function device_can_read_msg(can_device device_name, can_msg_package* tx_msg_package);
function device_can_write_msg(can_device device_name, can_msg_package* rx_msg_package);
function device_can_write_buffer(can_device device_name,unsigned int msg_id, unsigned char*buf,unsigned int length);

#endif /* __USB2CAN_DRIVER_H__*/

/************************ (C) END OF FILE ************************************/




